<?php
namespace frontend\controllers;

use Yii;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use frontend\models\Resume;
use frontend\models\Country;
use frontend\models\Education;
use frontend\models\Job;
use frontend\models\Langue;
use frontend\models\Company;
use frontend\models\Position;
	class MemberController extends Controller
	{   
       public $layout="mm.php";

        public function actionAccount()
       {
         return $this->render("account");
       }

       function actionResume()
       { 
         $uid = Yii::$app->user->identity->id;
          $model = Resume::find()->joinWith(['type'])->joinWith(['job'])->joinWith(['langue'])->select("*")->asArray()->all();
          $data= $model[0];
          //print_r($data);die;
         return $this->render("resume",[
              'data' => $data,
          ]);
       }

       function actionAdd()
       {  
         $uid = Yii::$app->user->identity->id;
         $connection = \Yii::$app->db;
         $command = $connection->createCommand('SELECT * FROM areas where parent_id =0');
         $area = $command->queryAll();
       // print_r($area);die;

         $model = new Resume();
          return $this->render('apply', [
               'model' => $model,
               'area'  => $area,
               'uid'   => $uid,
          ]);
       }

       function actionSelect()
       {
       	 return $this->render("select");
       }

       function actionInfo()
       {
       	 return $this->render("info");
       }

       function actionCity()
       {  
          $request = Yii::$app->request;

          $aid=$request->get(); 
          //print_r($aid);die;
          $id = $aid['id_'];
          $connection = \Yii::$app->db;
          $command = $connection->createCommand('SELECT * FROM areas where parent_id ='.$id);
          $area = $command->queryAll();
          if($area)
          {
             $data['msg'] =1;
             $data['area'] =$area;
          }
          else
          {
            $data['msg'] =0;
          }
          echo json_encode($data);

       }

       public function actionAdd_do()
       {  
          $model = new Resume();
          //会员ID
          $uid = Yii::$app->user->identity->id;
          $data = Yii::$app->request->post();
          if($model->load(Yii::$app->request->post()) && !empty($data['name']))
          {  
          
             $model->save();
          }

          return $this->render("lv",[
                'uid' => $uid,
            ]);


       }

       public function actionApply()
       {
          $emodel = new Education();
          $jmodel = new Job();
          $lmodel = new Langue();

           if(Yii::$app->request->post())
           { 
             $data = Yii::$app->request->post();
             $emodel->load($data);
             $emodel->save();
             $jmodel->load($data);
             $jmodel->save();
             $lmodel->load($data);
             $lmodel->save();


           }

          return $this->render("review");
       }


       public function actionReg()
       {  
         $uid = Yii::$app->user->identity->id;
          $model = new Company();
          
        if($model->load(Yii::$app->request->post()))
          {  
          
             $model->save();
           
          }

          return $this->render("reg",[
               'model'=>$model,
               'uid'  => $uid,
            ]);
       }

       function actionCompany_add()
       {  
         $cmodel = new Company();
        // $imodel = new Company_info();
         if($cmodel->load(Yii::$app->request->post()))
         {
           $cmodel->save();
           print_r($model);
         }
       }


       public function actionFa()
       { 
         $uid = Yii::$app->user->identity->id;
         $model = new Position();

          if($model->load(Yii::$app->request->post()))
          {
             $model->save();

          }
         return $this->render("fa",[
             'model' => $model,
             'mid'   => $uid,
          ]);
       }


	}